import React, { Component } from 'react'
import Cmp1 from '../Child/Cmp1'
import Cmp2 from '../Child/Cmp2'

import MyContext, { db } from '../context/Bus'

export default class Sub extends Component {
  constructor(props) {
    super(props);
    this.state = {
      user: db.user2
    }
  }


  render() {

    return (
      <MyContext.Provider value={this.state.user}>
        <Cmp1 />
        <Cmp2 />
        <button onClick={this.fn.bind(this)}>按钮一下</button>
      </MyContext.Provider>
    )
  }

  fn() {
    this.setState({
      user: db.user1
    })
  }
}
